<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view' );
jimport( 'joomla.html.parameter' );



class jzmluvyViewUpravaObjednavky extends Jview
{
	
  function display($tpl = null){
		global $mainframe, $option;
		
		$db 		=& JFactory::getDBO();
		$params	= &JComponentHelper::getParams('com_jzmluvy');
    $nastavenie = & jzmluvyHelper::nastavenie();
    		
		//get data from model
		$model		= & $this->getModel();
		$item     = & $this->get( 'Data');
		
		//*** zoznam partnerov
		$dod = array();   //*** TYP urcuje ze su vybrani len partneri 
    $query = 'SELECT *'
			. ' FROM #__jzmluvy_partner'
			. ' WHERE published = 1' // len povoleny zobrazit
      . ' AND typ = 1' // len dodavatelia
      . ' ORDER BY reserverd DESC, title ASC' // triedenie podla favorita, mena
		;
		$db->setQuery( $query ); 
		
		$dod[] = JHTML::_('select.option',  0 , ' - Vyber dodávateľa - ');
		foreach( $db->loadObjectList() as $obj )
		{
			$ident 	= $obj->reserverd ? ' *' : ''; // identifikacia favorita
			$dod[] = JHTML::_('select.option',  $obj->id, $obj->title.$ident);
		}
    $lists['dod'] = JHTML::_('select.genericlist', $dod, 'dodavatel', 'class="inputbox" size="1"', 'value', 'text', $item->dodavatel );
    
    //kontaktu
		$kontakty = array();
    $query = 'SELECT *'
			. ' FROM #__contact_details'
			. ' WHERE published = 1'
			. ' ORDER BY name'
		;
		$db->setQuery( $query );
		
    //*** zoznam kontaktov ... zodpovednych
		$kontakty[] = JHTML::_('select.option',  0 , '- Vyberte kontakt -');
		foreach( $db->loadObjectList() as $obj )
		{
			$kontakty[] = JHTML::_('select.option',  $obj->id, $obj->name);
		}
		$lists['kontakty'] 	= JHTML::_('select.genericlist', $kontakty, 'created_by_alias', 'class="inputbox" size="1"', 'value', 'text', $item->created_by_alias );  
		


    //*** identifikacia zmluvy
		$dodatok = array();  
    $query = 'SELECT *'
			. ' FROM #__jzmluvy'
			. ' WHERE catid = 2'
      . ' AND typ = 0'
      . ' ORDER BY faktura'
		;
		$db->setQuery( $query );
		
		$dodatok[] = JHTML::_('select.option',  0 , ' - Vyberte zmluvu - ');
		foreach( $db->loadObjectList() as $obj )
		{
		  // cislo zmluvy aj predmet .. skrateny na 30 naskov
      $vyb = $obj->faktura."-".trim(mb_substr($obj->fulltext, 0, 30, 'UTF-8')).'...';
    	$dodatok[] = JHTML::_('select.option',  $obj->id, $vyb);
		}
		$lists['dodatok'] 	= JHTML::_('select.genericlist',   $dodatok, 'typ', 'class="inputbox" size="1"', 'value', 'text', $item->typ );
   
   
    $this->assignRef('item', $item);
    $this->assignRef('params', $params);
    $this->assignRef('lists', $lists);
    $this->assignRef( 'nastavenie', $nastavenie );


		parent::display($tpl);

	}

}
?>